home *** CD-ROM | disk | FTP | other *** search
/ Software 2000 / Software 2000 Volume 1 (Disc 1 of 2).iso / utilities / u264.dms / in.adf / ARPPRO3.0 / PRO.RUN / gads.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-18  |  2.4 KB  |  97 lines

  1. /* Created 11/08/87 by -=+SDB+=- from cliparse.c provided by Manx */
  2. /* Copyright (C) 1987 by Scott Ballantyne */
  3. /* May be freely used by arp supporters/users */
  4.  
  5. /* This routine is called from _main() and parses the arguments passed from
  6.  * the CLI to the program.  It uses the ARP tracking functions to allocate
  7.  * memory for the argv array, and sets up _argc and _argv (using GADS)
  8.  * which will eventually be passed as parameters to main().
  9.  *
  10.  * It uses the Global variables CLI_Template and CLI_Help to set the command
  11.  * templates and extra help string for GADS() - if you don't set these up
  12.  * yourself, you get the defaults.
  13.  */
  14.  
  15. #include <libraries/dosextens.h>
  16.  
  17. extern int _argc;
  18. extern char **_argv;
  19. extern char *CLI_Template;
  20. extern char *CLI_Help;
  21. extern char *_detach_name;            /* for DETACHED programs */
  22.  
  23. _cli_parse(pp, alen, aptr)
  24. struct Process *pp;
  25. long alen;
  26. char *aptr;
  27. {
  28.     register char *cp;
  29.     register struct CommandLineInterface *cli;
  30.     register char *c;
  31.     register int argcount;
  32.     int length;
  33.     void *ArpAlloc();
  34.     long GADS();
  35.  
  36.     if (pp->pr_CLI) {
  37.         cli = (struct CommandLineInterface *) ((long)pp->pr_CLI << 2);
  38.         cp = (char *)((long)cli->cli_CommandName << 2);
  39.     }
  40.     else
  41.         cp = _detach_name;
  42.  
  43.     length = cp[0];         /* Length of command name */
  44.  
  45.     /* argcount *must* start at 3, do not change this.
  46.      * we need one for argv[0] = progname, and GADS() always
  47.      * requires one arg entry (for error messages, etc.)
  48.      * Then it is quasi standard for 'C' to have a final NULL as
  49.      * the argv array...
  50.      */
  51.     for (argcount = 3, c = CLI_Template; *c; c++ ) /* Size we need for argv */
  52.         if (*c == ',')
  53.             argcount++;
  54.  
  55.     if ((c = ArpAlloc((long)length)) == 0)  /* Get mem for name */
  56.         ArpExit(20L, ERROR_NO_FREE_STORE);
  57.     strncpy(c, cp+1, cp[0]);
  58.  
  59.     if ( (_argv = ArpAlloc( (long)(argcount * sizeof(*_argv)))) == 0)
  60.         ArpExit(20L, ERROR_NO_FREE_STORE);
  61.  
  62.     _argv[0] = c;
  63.     _argc = (int)GADS(aptr, alen, CLI_Help, (_argv+1), CLI_Template);
  64.     if (_argc < 0 )
  65.     {
  66.         Printf("Bad Args for %s: %s\n", _argv[0], _argv[1] );
  67.         ArpExit(20L, ERROR_LINE_TOO_LONG);
  68.     }
  69.     _argc++;
  70.  
  71. #if 0
  72.     if (GADS(aptr, alen, CLI_Help, (_argv+1), CLI_Template) < 0) {
  73.         Printf("Bad Args for %s: %s\n", _argv[0], _argv[1] );
  74.         ArpExit(20L, ERROR_LINE_TOO_LONG);
  75.     }
  76.  
  77.     _argc = countargs(argcount-1,_argv);
  78. #endif
  79. }
  80.  
  81. #if 0
  82.  
  83. static
  84. countargs (argc,argv)
  85. register int argc;
  86. register char **argv;
  87. {
  88.     argv += argc;
  89.  
  90.     while (--argc)
  91.     if (*(--argv)) break;
  92.  
  93.     return argc+1;
  94. }
  95.  
  96. #endif
  97.